/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.DAO;

import com.aptech.model.BankLoan;
import com.aptech.model.Directories;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author Hoang Quy Hong An
 */
public class DirectoryDAO {

    private Connection myCon = null;
    private PreparedStatement ps = null;
    private ResultSet rs = null;
    private String strCommand = "";

    public ArrayList<Directories> getDirectoryByCateID(int DrCID) {
        ArrayList<Directories> listDirectories = new ArrayList<Directories>();
        strCommand = "SELECT directoryID ,directoryCategoryID ,directoryName ,directoryAddress ,"
                + " directoryPhone ,directoryEmail"
                + " FROM tbl_Directories WHERE directoryCategoryID = ? AND directoryStatus = 1";
        Directories objDirectories = null;
        try {
            myCon = myConnection.getConnection();
            ps = myCon.prepareStatement(strCommand, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            ps.setInt(1, DrCID);
            rs = ps.executeQuery();
            while (rs.next()) {
                objDirectories = new Directories();
                objDirectories.setDirectoryID(rs.getInt("directoryID"));
                objDirectories.setDirectoryCategoryID(DrCID);
                objDirectories.setDirectoryName(rs.getString("directoryName"));;
                objDirectories.setDirectoryAddress(rs.getString("directoryAddress"));;
                objDirectories.setDirectoryPhone(rs.getString("directoryPhone"));
                objDirectories.setDirectoryEmail(rs.getString("directoryEmail"));
                listDirectories.add(objDirectories);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            myConnection.closeConnection(myCon, ps, rs);
        }
        return listDirectories;
    }
}
